/*
 * BlackLightning.SFGameServer
 * Andy Tidball
 * 
 * Project: Black Lightning
 * Copyright: GNU General Public License
 */

using System;
using BlackLightning.PluginLib.Modules;
using BLLib.Net;

namespace BlackLightning {
	/// <summary>
	/// A game server which communicates using the StormFront XML protocol.
	/// </summary>
	class SFGameServer : GameServer {
		/// <summary>
		/// Creates a new GameServer.
		/// </summary>
		/// <param name="Connection">An already connected and handshaked connection to the game server.</param>
		/// <param name="FirstConnection">True if this is the first time connecting to a game server this run.</param>
		public SFGameServer(Connection Connection, bool FirstConnection)
			: base(Connection, "\n", true, "\n", "\n") {
		}

		/// <summary>
		/// Sends the given packet to the game server.
		/// </summary>
		/// <param name="Packet">The packet to send to the game server.</param>
		public override void SendPacket(Packet Packet) {
			if (Packet.RawInput == "<c>" + Environment.NewLine) {
				base.PacketTerminator = "\r\n";
				base.ReceiveNewLine = "\r\n";
			}
			base.SendPacket(Packet);
		}

		/// <summary>
		/// Creates a Packet from the game server and headed for the front end.
		/// </summary>
		/// <param name="Data">The data to initialize the packet with.</param>
		protected override Packet CreatePacket(string Data) {
			return new RawBLPacket(Program.GameServer, Program.FrontEnd, Data);
		}
	}
}
